package com.example.demo.service;

import com.example.demo.mapper.LinkMapper;
import com.example.demo.pojo.Link;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

@Service
public class LinkService {
    @Autowired
    private LinkService linkService;
    @Autowired
    private LinkMapper linkMapper;

    public void save(Link link){
        linkMapper.insert(link);
    }

    public PageInfo findByPage(int size,int page){
        PageHelper.startPage(page,size);//分页

        List<Link> list = linkMapper.selectAll();//查询指定页码的数据

        PageInfo PageInfo = new PageInfo<>(list);//将数据封装
        return PageInfo;
    }
    public void delete(Link link){//删除具体的元组
        linkMapper.delete(link );
    }

    public void delete1(int id){//根据主键删除
        linkMapper.deleteByPrimaryKey(id);
    }

    public void update(Link link){
        linkMapper.updateByPrimaryKey(link);
    }

    public Link select(int id){
       Link link= linkMapper.selectByPrimaryKey(id);
        return link;
    }

}
